package com.company.jdk.stream;

import java.util.Arrays;
import java.util.stream.Collectors;

/**
 * @author yingfing
 * @create 2020--10--04 17:26
 * @describe
 */
public class TestStream1 {
    public static void main(String[] args) {
        // 流操作
        /**
         * 1.中间操作
         * map\映射
         * flatmap\扁平化
         * filter\过滤条件
         * limit\截取个数
         * skip\跳过的个数
         * distinct\去重
         * sorted\排序
         *
         * 2.终端操作
         * 2.1 forEach\forEachOrdered   遍历
         * 2.2 anyMatch\allMatch\noneMatch\findFirst\findAny    匹配
         * 2.3 min\max\count\average
         * 2.4 reduce
         * 2.5 collect  collectors
         */
        Arrays.asList(1, 2, 3, 3, 56, 4, 88, 65).stream();
        //.filter(x->x%2==0)
        //.skip(3)
        //.limit(5)
        //.distinct()
        //.sorted()
        //.sorted(new Comparator(){...})
        //.map(x->Math.pow(x,2))
        //.flatMap(x->Stream.of(x))
        //.forEach(x->System.out.println(x))
        //.forEach(System.out::println);

        Arrays.asList(
                new Integer[]{1, 3, 2},
                new Integer[]{11, 23, 65}
        ).stream();
//                .flatMap(x -> Arrays.stream(x));
//                .forEach(System.out::println);
//                .anyMatch(x -> x == 1);
//                .allMatch(x -> 1);
//                .noneMatch(x -> x < 0);
//                .findFirst();
//                .max(new Comparator<Integer>() {
//                    @Override
//                    public int compare(Integer o1, Integer o2) {
//                        return o1 - o2;
//                    }
//                })
//                .count();
//        System.out.println(max.get());
//        System.out.println(count);

        Double collect = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0).stream()
                .skip(2)
                .limit(5)
                .distinct()
                // .reduce(0,(x,y)->x+y)
                //.collect(Collectors.toList())
                //.collect(Collectors.toSet())
                //.collect(Collectors.toMap(x -> x, x -> 1))
                .collect(Collectors.averagingDouble(x -> x.doubleValue()));
//        System.out.println(result);
        System.out.println(collect);
    }

}

class Student {
}
